package com.kantboot.user.admin.domain.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 管理员路由实体类
 * 用于前端动态路由
 * @author 方某方
 */
@Entity
@Getter
@Setter
@Table(name = "user_account_admin_router")
@Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@DynamicInsert
public class UserAdminRouter implements Serializable {

    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "gmt_create")
    private Date gmtCreate;

    /**
     * 修改时间
     */
    @LastModifiedDate
    @Column(name = "gmt_modified")
    private Date gmtModified;

    /**
     * 路由标题
     */
    @Column(name = "t_title", length = 64)
    private String title;

    /**
     * 路由路径
     */
    @Column(name = "t_path", length = 64)
    private String path;

    /**
     * 路由优先级
     */
    @Column(name = "t_priority")
    private Integer priority;

    /**
     * 路由图标id
     */
    @Column(name = "file_id_of_icon")
    private Long fileIdOfIcon;

    /**
     * 父ID
     */
    @Column(name = "parent_id")
    private Long parentId;

    /**
     * children
     */
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "parent_id", insertable = false, updatable = false)
    @OrderBy("priority DESC")
    private List<UserAdminRouter> children;

}
